<?php

/**

 * 秒杀商品服务层

 * @author maniac

 */

namespace app\common\service;

use app\common\model\Spike AS SpikeModel;


class Spike extends Base
{

    /**
     * 获取可购买的秒杀商品列表
     */
    public function spike($where,$limit)
    {
    	$data  = \think\Db::field('spike.id,spike.goods_id,spike.goods_name spike_name,spike.describe spike_describe,spike.promotion_price,spike.pbegin,spike.pend,spike.num,goods.goods_name,goods.goods_thumb_id,goods.sale_price')
    	
    	->table(['maniac_spike'=>'spike','maniac_goods'=>'goods'])
    	->where('spike.goods_id=goods.id')
    	->where($where)
    	->limit($limit)
    	->select();
    	
       	foreach ($data as $key => $value) {
    		$data[$key]['image_uri']=getimg($value['goods_thumb_id']);

            //是否开始
            $data[$key]['is_group']=0;//是否开团：0否，1是开团
            if($value['pbegin']<time()){
                $data[$key]['is_group']=1;
            }
       	}
    	
        return $data;
        
    }
    /**
    
    * 获取秒杀商品详情
    * * @param array  $where 查询条件
    
    */
    public function detail($where)
    {
        return SpikeModel::field('id,goods_name,describe,goods_id,promotion_price,pbegin,pend,num,all_num,goods_thumb_id,sale_price')->append(['image_uri'])->where($where)->find();
    }

}

